/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package view.ihm;

import mod.dao.membre;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
import javax.swing.JOptionPane;

/**
 *
 * @author willy
 */
public class guiAuth extends JApplet implements ActionListener{
    PanAuth pan;
    Load game;
    public guiAuth()
    {
        pan=new PanAuth();
        add(pan);
        //setLocationRelativeTo(null);
        setVisible(true);
        //setResizable(false);
        pan.bt_ok.addActionListener(this);
        //setTitle("P. G: Authentification");
        
    }

    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==pan.bt_ok) bt_okActionPerformed(e);
        //this.dispose();
    }



    private void bt_okActionPerformed(java.awt.event.ActionEvent evt) {

    membre m=new membre(pan.txt_login.getText(), pan.txt_pass.getText());
        m=m.getAuthentification();
        if(m!=null)
        {
            this.remove(pan);
            this.setSize(600,400);
            this.add(new guiTable(m,this));
            this.repaint();
            this.validate();

            //JApplet jf=new JApplet();
            //jf.add(new guiTable(m));
            //jf.setSize(600,400);
            //jf.setLocationRelativeTo(null);
            //jf.setVisible(true);
            //jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //this.dispose();
        }
        else
        {
            System.out.println("Non connecté m="+m);
            JOptionPane.showMessageDialog(null,
                "Paramètres de connexion érronés",
                "Erreur de connexion",
                JOptionPane.ERROR_MESSAGE);

        }
        

        // TODO add your handling code here:
    }

    public void init() {
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    new guiAuth();
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    @Override
    public void destroy() {
        if(game!=null)
        {
            game.Arret();
        }
        super.destroy();
    }

}
